package com.kou.service.impl;

import com.kou.dao.GoodsTypeDao;
import com.kou.dao.GoodsTypeDaoImpl;
import com.kou.pojo.Type;
import com.kou.service.GoodsTypeService;
import com.kou.utils.DataSourceUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

/**
 * @author SteinY
 * @create 2022-03-28 10:32
 * @description:
 */
public class GoodsTypeServiceImpl implements GoodsTypeService {
    QueryRunner queryRunner = new QueryRunner();
    GoodsTypeDao goodsTypeDao = new GoodsTypeDaoImpl();
    @Override
    public List<Type> findTypes() {
        Connection connection = DataSourceUtil.getConnection();
        String sql ="select * from tb_goods_type";
        try {
            return queryRunner.query(connection,sql,new BeanListHandler<>(Type.class));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public String findParentName(Integer parent) {
        return goodsTypeDao.findParentName(parent);
    }

    @Override
    public String findTypeName(int id) {
        return goodsTypeDao.findTypeName(id);

    }
}
